<?php

namespace App\Http\Requests\Permission;

use App\Http\Requests\ApiRequest;
use Illuminate\Validation\Rule;

class UpdateRequest extends ApiRequest
{
    /**
     * 'update'：前端路由
     *
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return self::checkPermission('update');
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => 'required|integer',
            'name' => 'string',
            'type' => ['required', 'integer', Rule::in([0, 1])],
            'description' => 'required|string'
        ];
    }

    public function messages()
    {
        return [
            'id.required' => '缺少ID',
            'id.integer' => 'ID必须为整数',
            'name.string'=>'权限名称必须为字符类型',
            'description.required' => '请填写权限描述',
            'description.string' => '权限描述必须为字符类型',
            'type.integer'=>'权限类型必须为整型',//权限类型 默认0-action类 1-menu类
        ];
    }
}
